package me.zk.practice1.thread;

import java.util.concurrent.*;
import java.util.function.BiConsumer;

/**
 * @author zhangkai
 * @date 2023/7/31 18:08
 */
public class CompletableFutureDemo {

    static ThreadPoolExecutor executor = new ThreadPoolExecutor(5,10,1, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(200),new ThreadPoolExecutor.AbortPolicy());
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture.runAsync(()->System.out.println("任务一执行:"+Thread.currentThread().getName()),executor)
                .whenCompleteAsync((unused, throwable) -> {

                });

        CompletableFuture<Integer> future2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务二执行:" + Thread.currentThread().getName());
            return 10;

        }, executor).whenCompleteAsync((res, throwable) -> {
            System.out.println("任务二子线程执行:" + Thread.currentThread().getName());
            System.out.println("任务二子线程结果:" + res);

        },executor);
        System.out.println("main线程end:" + future2.get());
        executor.shutdown();
    }
}
